package com.jeeplus.modules.web.web;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.modules.web.entity.WxAgents;
import com.jeeplus.modules.web.entity.YjEquipment;
import com.jeeplus.modules.web.mapper.AnalyseMapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "${adminPath}/web/analyse")
public class AnalyseController extends BaseController {

    @Autowired
    private AnalyseMapper analyseMapper;

    @RequiresPermissions("web:analyse:area")
    @RequestMapping(value = { "area", "" })
    public String list(Integer pageIndex, Model model, YjEquipment yjEquipment) {
        return "modules/web/analyseArea";
    }

    /**
     * 设备信息列表数据
     */
    @ResponseBody
    @RequiresPermissions("web:analyse:area")
    @RequestMapping(value = "areaData")
    public Map<String, Object> data(HttpServletRequest request, HttpServletResponse response,String startDate,String endDate) {
        Page<Map> objectPage = new Page<>(request, response);
        List<Map> data = analyseMapper.findData(startDate, endDate);
        objectPage.setList(data);
        return getBootstrapData(objectPage);
    }

    @RequiresPermissions("web:analyse:store")
    @RequestMapping(value = "store")
    public String store(Integer pageIndex, Model model, YjEquipment yjEquipment) {
        return "modules/web/analyseStore";
    }

    /**
     * 设备信息列表数据
     */
    @ResponseBody
    @RequiresPermissions("web:analyse:store")
    @RequestMapping(value = "storeData")
    public Map<String, Object> storeData(HttpServletRequest request, HttpServletResponse response, String startDate, String endDate, WxAgents wxAgents) {
        Page<Map> objectPage = new Page<>(request, response);
        List<Map> data = analyseMapper.findStoreDate(startDate, endDate,wxAgents);
        objectPage.setList(data);
        return getBootstrapData(objectPage);
    }
}
